import React, { Component } from 'react';
import { Form, Input, Button, Toast } from 'antd-mobile'
import '../../styles/Pass.scss'
import service from '../../api'
class pass extends Component {
    constructor(props) {
        super(props)
        this.state = {
            password: '',
            tel: ''
        }
    }

    back() {
        this.props.history.go(-1)
    }
    onChange(e) {
        this.setState({

            [e.target.name]: e.target.type == 'checkbox' ? e.target.checked : e.target.value
        })
    }
    async topass() {
        var reg = /^\d{4}$/
        var res = reg.test(this.state.password)
        if (this.state.password == '') {
            Toast.show('密码不能为空')
        } else {
            if (!res) {
                Toast.show('格式错误')
            } else {

                var res1 = await service.users.user_dofinishregister({ tel: this.props.location.state.tel,password: this.state.password })
                if(res1.data.code==200){
                    Toast.show('注册成功')
                    this.props.history.push({ pathname: '/login', state: { tel: this.props.location.state.tel, password: this.state.password } })
                }
            }
        }

    }
    render() {

        return (
            <div className='pass'>
                <div className="tu">
                    <div className='iconfont icon-tupianjiazaishibai03'></div>
                    <div>请设置密码</div>
                </div>
                <div className="inp">
                    <input type="password" name='password' placeholder='请设置至少4位登陆密码' value={this.state.password} onChange={(e) => { this.onChange(e) }} />
                    <span className='iconfont icon-iconfont32pxmimabukejian'></span>
                </div>
                <div className="text">
                    密码强度校验，最少四位

                </div>
                <div className="btn">
                    <Button block size='large' onClick={() => { this.topass() }}>
                        完成
                    </Button>
                </div>
            </div>
        );
    }
}

export default pass;